#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,a[1000005],p[1000005];
signed main(){
  freopen("color.in","r",stdin);
  freopen("color.out","w",stdout);
  scanf("%lld",&t);
  while(t--){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
      scanf("%lld",&a[i]);
    }
    int ans=0;
    for(int x=0;x<(1<<n);x++){
        for(int i=0;i<n;i++){
          if(x&(1<<i)){
            p[i+1]=1;
          }
          else p[i+1]=2;
        }
        int t1=0,t2=0,sum=0;
        if(p[1]==1)t1=a[1];
        else t2=a[1];
        for(int i=2;i<=n;i++){
            if(p[i]==1){
                if(a[i]==t1)sum+=a[i];
                t1=a[i];
            }
            else{
                if(a[i]==t2)sum+=a[i];
                t2=a[i];
            }
        }
        ans=max(ans,sum);
        for(int i=1;i<=n;i++)p[i]=0;
    }
    printf("%lld\n",ans);
  }
  return 0;
}
/*
2
15
5 3 7 2 4 13 11 6 5 5 3 5 12 8 13
15
1 12 11 11 7 11 15 6 4 6 3 15 7 5 2
*/
